package com.Zhengxin.smarthome;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;

public class AlarmAlert extends Activity{
	private String todolist;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		new AlertDialog.Builder(AlarmAlert.this).setTitle("alarm ran")
		.setPositiveButton("Close", new OnClickListener() {
			
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				AlarmAlert.this.finish();
			}
		}).show();
		
		//FileOutputStream fos = null;
		FileInputStream fIn = null;  
		InputStreamReader isr = null;  

		char[] inputBuffer = new char[4];  
		String todolist = null;  

		try{  
		fIn = openFileInput("todolist.txt");   
		isr = new InputStreamReader(fIn);  
		isr.read(inputBuffer);  
		todolist = new String(inputBuffer);
		
		fIn.close();
		isr.close();
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		System.out.println(todolist);
		
		if(Integer.parseInt(String.valueOf(todolist.charAt(0)))==1){
			Intent intent= new Intent(AlarmAlert.this,ConnectService.class);
			Bundle bundle= new Bundle();
			bundle.putString("config","MirMe_CONTROL_TURNON");
			intent.putExtras(bundle);
			startService(intent);
		}
		
		if(Integer.parseInt(String.valueOf(todolist.charAt(1)))==1){
			Intent intent= new Intent(AlarmAlert.this,ConnectService.class);
			Bundle bundle= new Bundle();
			bundle.putString("config","Light_CONTROL_TURNOFF");
			intent.putExtras(bundle);
			startService(intent);
		}
		
		if(Integer.parseInt(String.valueOf(todolist.charAt(2)))==1){
			Intent intent= new Intent(AlarmAlert.this,ConnectService.class);
			Bundle bundle= new Bundle();
			bundle.putString("config","Music_CONTROL_Run");
			intent.putExtras(bundle);
			startService(intent);
		}
		
		if(Integer.parseInt(String.valueOf(todolist.charAt(3)))==1){
			Intent intent= new Intent(AlarmAlert.this,ConnectService.class);
			Bundle bundle= new Bundle();
			bundle.putString("config","WaterHeater_CONTROL_Run");
			intent.putExtras(bundle);
			startService(intent);
		}
		
		
		
	}

}
